﻿using EasyNetQ;
using Magic.Rmq;
using Microsoft.Extensions.DependencyInjection;

namespace RabbitmqTest;

/// <summary>
/// 消费者
/// </summary>
public class 测试消息 : RmqConsumerWorkerBase<string>
{

    public 测试消息(int threadCount)
    {
        this.QueueName = "测试消息";
        this.ConsumerCount = threadCount;
    }
    protected override async Task HandleComingMessage(string model)
    {

        Console.WriteLine($"{DateTime.Now.ToString()}:接到消息【{model}】");
        Console.WriteLine("蛋蛋好人一生平安，大富大贵");
    }
}

internal class Program
{
    static async Task Main(string[] args)
    {
        IServiceCollection services = new ServiceCollection();
        services.AddRmq("host=101.35.232.57;Port=5672;virtualHost=magic;username=swsk33;password=123456");

        await RmqProvider.AddQueue("测试消息", $"测试消息_死信", TimeSpan.FromSeconds(10));

        // 订阅消息队列
        await new 测试消息(10).StartWithAck();

        Console.WriteLine("启动成功");

    H:
        Console.WriteLine("请输入要发送的消息");


        await RmqProvider.EnqueueAsync(Console.ReadLine().ToString(), "测试消息");


        goto H;

        
    }

   

}
